<template>
	<view class="change_popup">
		<view class="close" @click="$emit('close')">
			<image :src="`${baseImageUrl}/common/close1.png`"></image>
		</view>
		<view class="title">
			<view>转入{{item.name}}</view>
		</view>
		<view class="content">
			<view class="total">
				<text>可购买总数:{{total}}颗</text>
				<view class="btn" @click="number=total">全买</view>
			</view>
			<view class="number">
				<view class="icon" @click="reduce">
					<image :src="`${baseImageUrl}/common/js.png`"></image>
				</view>
				<input type="text" placeholder="单行输入" v-model="number">
				<view class="icon" @click="add">
					<image :src="`${baseImageUrl}/common/zj.png`"></image>
				</view>
			</view>

			<!-- <view class="price">预计可得：￥0.00</view> -->
		</view>
		<view class="btn_view">
			<view class="cancel" @click="$emit('close')">取消</view>
			<view class="confirm" @click="submit">确定</view>
		</view>
	</view>
</template>

<script>
	// import {
	// 	captchaAppId
	// } from '@/utils/config.js';
	import {
		ticketDeposit
	} from '@/request/api.js';
	export default {
		props: {
			total: {
				type: [Number, String],
				default: 0
			},
			item: {
				type: Object,
				default: {}
			}
		},
		data() {
			return {
				number: ""
			}
		},
		methods: {
			reduce() {
				if (this.number == 0) {
					this.$u.toast("不可减少了");
					return false;
				}
				this.number--
			},
			add() {
				if (this.number >= this.total) {
					this.$u.toast("不可增加了");
					return false;
				}
				this.number++;
			},
			async submit() {
				if (this.number <= 0) {
					this.$u.toast("请输入数量");
					return false;
				}
				// const captcha = new TencentCaptcha(captchaAppId, async (data) => {
				// 	if (data.ret !== 0) return false;
				// 	let {
				// 		randstr,
				// 		ticket
				// 	} = data;
				await ticketDeposit({
					id: this.item.id,
					number: this.number
				});
				this.$u.toast("操作成功");
				setTimeout(() => {
					this.$emit('close');
				}, 1000);
				// }, {});
				// captcha.show();
			}
		}
	}
</script>

<style scoped lang="scss">
	.change_popup {
		width: 630rpx;
		height: 480rpx;
		padding: 42rpx 0 52rpx;
		box-sizing: border-box;
		background: url(#{$baseImageUrl}/bg/630_630.png) no-repeat;
		background-size: 100% 100%;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		position: relative;

		.close {
			width: 122rpx;
			height: 122rpx;
			position: absolute;
			right: 0rpx;
			top: 0rpx;
			transform: translate(50rpx, -50rpx);
			z-index: 2;

			image {
				width: 100%;
				height: 100%;
			}
		}

		.title {
			display: flex;
			justify-content: center;
			align-items: center;

			view {
				width: 256rpx;
				height: 30rpx;
				line-height: 30rpx;
				text-align: center;
				color: #494338;
				font-size: 42rpx;
				font-weight: 400;
				font-family: LiSu;
				background: url(#{$baseImageUrl}/home/title.png) no-repeat;
				background-size: 100% 100%;
			}
		}

		.content {
			.total {
				display: flex;
				justify-content: center;
				align-items: center;

				text {
					color: #494338;
					font-size: 28rpx;
					font-weight: 400;
					font-family: SimSun;
				}

				.btn {
					width: 92rpx;
					height: 44rpx;
					line-height: 44rpx;
					text-align: center;
					color: #756768;
					font-size: 28rpx;
					font-weight: 400;
					font-family: SimSun;
					margin-left: 16rpx;
					background: url(#{$baseImageUrl}/common/btn4.png) no-repeat;
					background-size: 100% 100%;
				}
			}

			.number {
				height: 80rpx;
				margin: 36rpx 0 60rpx;
				padding: 0 35rpx;
				box-sizing: border-box;
				display: flex;

				.icon {
					width: 80rpx;
					height: 80rpx;

					image {
						width: 100%;
						height: 100%;
					}
				}

				input {
					flex: 1;
					height: 80rpx;
					color: #494338;
					font-size: 28rpx;
					font-weight: 400;
					font-family: SimSun;
					border-radius: 10rpx;
					box-shadow: 2rpx -1rpx 10rpx 0px rgba(3, 0, 0, 0.2);
					padding-left: 40rpx;
					box-sizing: border-box;
					background: #C0B5B6;
				}
			}

			.price {
				text-align: center;
				color: #494338;
				font-size: 28rpx;
				font-weight: 400;
				font-family: SimSun;
			}
		}

		.btn_view {
			width: 100%;
			display: flex;
			justify-content: center;

			view {
				width: 210rpx;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				color: #FFFFFF;
				font-size: 30rpx;
				font-weight: 400;
				margin: 0 16rpx;
			}

			.cancel {
				background: url(#{$baseImageUrl}/common/btn2.png) no-repeat;
				background-size: 100% 100%;
			}

			.confirm {
				background: url(#{$baseImageUrl}/common/btn.png) no-repeat;
				background-size: 100% 100%;
			}
		}
	}
</style>